﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.Collections;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TFEK02
    {
        
        ITXEXRPT ITXEXRPT;
        public TFEK02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VEKPOS();
            this.DataContext = MV;
            InitializeComponent();
           
            


        }
        
        
        
        public override void Query_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Return || e.Key != System.Windows.Input.Key.Enter)
                return;
            QueryCommand(null, null);
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
            
        {
            //string a = "";
            //a = txtTPY.Text.Trim();
            
            if (DTSTART == "")
            {
                DTSTART = "20000000";
            }
            if (DTEND == "")
            {
                DTEND = "99999999";
            }

            TBMain.Clear();
            dwData = TBMain.NewRow(); 
            dwData["EKPMANDANT"] = app.Mandant;
            string koll = "";
            if (KOLL.Trim() =="")
            {
                koll = ") X WHERE X.KOLL LIKE '%" + KOLL.Trim() + "%' or X.KOLL IS null";
            }
            else { koll = ") X WHERE X.KOLL LIKE '%" + KOLL.Trim() + "%' "; }
            dwData["EKPAUFKRS"] = " AND EKPAUFKRS LIKE '%" + KRS.Trim() + "%'"
                  + " AND EKPAUFLFD LIKE '%" + LFD.Trim() + "%'"
                  + " AND EKPAUFPOS LIKE '%" + POS.Trim() + "%'"
                  + " AND EKPLIEFNR LIKE '" + DES.Trim() + "%'"
                  + " AND EKPLTERM  >=" + DTSTART + ""
                  + " AND EKPLTERM  <=" + DTEND + ""
                  + " AND utl_raw.cast_to_varchar2(EKPART) LIKE '%" + ART.Trim() + "%'"
            + " AND EKKAUFART LIKE '%" + AUFART.Trim() + "%'" + koll;
             
            SResult = TMV.QEK0901(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
            IsQuery = false;
        }
        private void QueryByVKAUF(object sender, RoutedEventArgs e)
        {
            if (!IsQuery)
            {
                IsQuery = true;
            }
            dwData = TMV.MUX.TBMain.NewRow();
            dwData["ABAMANDANT"] = app.Mandant;
            dwData["ABAVKAUFKRS"] = INFO;
            SResult = TMV.QEK11(dwData);
            MergeData(SResult, true);
            base.QueryCommand(sender, e);
            IsQuery = false;
        }

        private void PrintCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.dsSource.Merge(MV.SetProd);
                //ITXEXRPT.dsSource.Merge(Se.Env);

                ITXEXRPT.DocType = "TSTEK02";

                ITXEXRPT.strExcelFile = @"TST\TSTEK02.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }



    }
}
